/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Gui;
import Gui.Main.tamthoi;
import hibernate.Dao.crawlerDao;
import hibernate.util.HibernateUtil;
import htmlunit.code.*;
import htmlunit.mode.*;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
/**
 *
 * @author TiTa
 */
public class Main extends javax.swing.JFrame {
 private static String QUERY_BASED_ON_FIRST_NAME1="from ThamSo a where a.tenThamso like '";
 private static String QUERY_BASED_ON_FIRST_NAME="from Link a where a.duongLink like '";
   
    public Main() {
        initComponents();
        load_table_link();
          jProgressBar2.setIndeterminate(true);
       jProgressBar1.setString("crawler");
    
        jProgressBar1.setStringPainted(true);
     //   bnt_thuthap.addActionListener(new ActionListener() {
    //  public void actionPerformed(ActionEvent e) {
     
      //  }
      
      
   // });
    }

  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        button1 = new java.awt.Button();
        jToolBar1 = new javax.swing.JToolBar();
        jLabel2 = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tb_ketqua_link = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        txt_tieude = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txt_link = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txt_tukhoa = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        sp_soluong = new javax.swing.JSpinner();
        jLabel4 = new javax.swing.JLabel();
        bnt_thuthap = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jProgressBar2 = new javax.swing.JProgressBar();
        jButton2 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tb_qldb = new javax.swing.JTable();
        bnt_xoa_qldb = new javax.swing.JButton();
        bnt_lammoi = new javax.swing.JButton();
        bnt_next = new javax.swing.JButton();
        btn_back = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        la_soluong = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();

        button1.setLabel("button1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jToolBar1.setRollover(true);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel2.setText("Fetch link");
        jToolBar1.add(jLabel2);

        tb_ketqua_link.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tb_ketqua_link.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tb_ketqua_linkMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tb_ketqua_link);

        jLabel5.setText("tiêu đề");

        jLabel6.setText("Link");

        jButton1.setText("tim kiem");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txt_tieude)
                            .addComponent(txt_link, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 675, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(278, 278, 278)
                        .addComponent(jButton1)))
                .addContainerGap(133, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txt_tieude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txt_link, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap(36, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Link Kết Quả", jPanel2);

        jLabel1.setText("Từ Khoá");

        txt_tukhoa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txt_tukhoaMouseClicked(evt);
            }
        });

        jLabel3.setText("so luong");

        sp_soluong.setValue(20);

        jLabel4.setText("tien trinh");

        bnt_thuthap.setText("thu thap");
        bnt_thuthap.setToolTipText("thu thap thong tin");
        bnt_thuthap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bnt_thuthapActionPerformed(evt);
            }
        });

        jProgressBar1.setForeground(new java.awt.Color(0, 102, 255));

        jButton2.setText("jButton2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txt_tukhoa, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(sp_soluong, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(122, 122, 122)
                        .addComponent(jLabel4))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(102, 102, 102)
                        .addComponent(jButton2)
                        .addGap(127, 127, 127)
                        .addComponent(bnt_thuthap))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(141, 141, 141)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(316, Short.MAX_VALUE))
            .addComponent(jProgressBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jProgressBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_tukhoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(sp_soluong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bnt_thuthap)
                    .addComponent(jButton2))
                .addContainerGap(94, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Lấy Link", jPanel1);

        tb_qldb.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tb_qldb);

        bnt_xoa_qldb.setText("xoa");

        bnt_lammoi.setText("lam moi");
        bnt_lammoi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bnt_lammoiActionPerformed(evt);
            }
        });

        bnt_next.setText("Next");
        bnt_next.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bnt_nextActionPerformed(evt);
            }
        });

        btn_back.setText("Back");
        btn_back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_backActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(236, 236, 236)
                        .addComponent(bnt_xoa_qldb)
                        .addGap(92, 92, 92)
                        .addComponent(btn_back)
                        .addGap(36, 36, 36)
                        .addComponent(bnt_next)
                        .addGap(33, 33, 33)
                        .addComponent(bnt_lammoi)))
                .addContainerGap(127, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bnt_xoa_qldb)
                    .addComponent(bnt_lammoi)
                    .addComponent(bnt_next)
                    .addComponent(btn_back))
                .addContainerGap(72, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Quản Lý Database", jPanel3);

        jLabel12.setText("so luong");

        jLabel11.setText("so luong");

        la_soluong.setText("so luong");

        jLabel8.setText("Số_Địa_chỉ_trong_csdl:");

        jLabel9.setText("So_Hình_trong_csdl:");

        jLabel10.setText("So_Link_trong_csdl:");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10))
                .addGap(36, 36, 36)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(la_soluong)
                    .addComponent(jLabel12)
                    .addComponent(jLabel11))
                .addContainerGap(594, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(la_soluong))
                .addGap(19, 19, 19)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel12))
                .addContainerGap(191, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Thống Kê", jPanel5);

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Chỉnh sửa");
        jMenuBar1.add(jMenu2);

        jMenu3.setText("Điều kiển");
        jMenuBar1.add(jMenu3);

        jMenu5.setText("Quản lý CSDL");
        jMenuBar1.add(jMenu5);

        jMenu4.setText("Trợ giúp");
        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
private void runQueryBasedOnFirstName() {
    executeHQLQuery(QUERY_BASED_ON_FIRST_NAME + txt_tieude.getText() + "%'");
}
//private JProgressBar pb_link;

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(!txt_tieude.getText().trim().equals("")) {
            runQueryBasedOnFirstName();
    }//GEN-LAST:event_jButton1ActionPerformed
    }
private void executeHQLQuery(String hql)
    {
        try {
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Query q = session.createQuery(hql);
        List resultList = q.list();
        displayResult(resultList);
        session.getTransaction().commit();
     } catch (HibernateException he) {
        he.printStackTrace();
    }
}
    private void displayResult(List resultList) {
    Vector<String> tableHeaders = new Vector<String>();
    Vector tableData = new Vector();
    tableHeaders.add("Mã Link"); 
    tableHeaders.add("Đường Link");
    tableHeaders.add("Tên Web");
    tableHeaders.add("Tình trạng");
   // tableHeaders.add("LastUpdated");

    for(Object doituong : resultList){
        Link actor = (Link)doituong;
        Vector<Object> oneRow = new Vector<Object>();
        oneRow.add(actor.getMaLink());
        oneRow.add(actor.getDuongLink());
        oneRow.add(actor.getTenWeb());
        oneRow.add(actor.getTinhTrang());
       
        tableData.add(oneRow);
    }
    tb_ketqua_link.setModel(new DefaultTableModel(tableData, tableHeaders));
    tb_ketqua_link.repaint();
   
}
    
private crawlerDao cd =new crawlerDao();
    /**
     * Creates new form NewJFrame
     */
   
 public void load_table_link(){
    DefaultTableModel dtm=new DefaultTableModel();
    
    dtm.addColumn("Ma link");
    dtm.addColumn("ten Web");
    dtm.addColumn("duong linh");
    dtm.addColumn("tinh trang");
    
    for(Link l:this.cd.danhsach_tatca_linl()){
        dtm.addRow(new Object[]{l.getMaLink(),l.getTenWeb(),l.getDuongLink(),l.getTinhTrang()});
    
    }
    this.tb_ketqua_link.setModel(dtm);
      this.tb_qldb.setModel(dtm);
    this.tb_ketqua_link.repaint();
    this.tb_ketqua_link.revalidate();
    }
 public void load_table_hinh(){
    DefaultTableModel dtm=new DefaultTableModel();
    
    dtm.addColumn("Ma hinh");
    dtm.addColumn("link hinh");
    dtm.addColumn("ten hinh");
    dtm.addColumn("dia chi luu");
    
    for(Hinh l:this.cd.danhsach_tatca_hinh()){
        dtm.addRow(new Object[]{l.getMaHinh(),l.getLinkHinh(),l.getTenHinh(),l.getDiaChiTrenMay()});
    
    }
    this.tb_qldb.setModel(dtm);
    
    this.tb_qldb.repaint();
    this.tb_qldb.revalidate();
    }
 public void load_table_thongtin(){
    DefaultTableModel dtm=new DefaultTableModel();
    
    dtm.addColumn("Ma thong tin");
    dtm.addColumn("dia chi");
    dtm.addColumn("dien thoai");
    dtm.addColumn("ten quan");
     dtm.addColumn("so nguoi like");
    
    for(ThongTin l:this.cd.danhsach_tatca_thongtin()){
        dtm.addRow(new Object[]{l.getMaThongTin(),l.getDiaChi(),l.getDienThoai(),l.getTenQuan(),l.getSoNguoiLike() });
    
    }
    this.tb_qldb.setModel(dtm);
    this.tb_qldb.repaint();
    this.tb_qldb.revalidate();
    }
 public void load_table_thamso(){
    DefaultTableModel dtm=new DefaultTableModel();
    dtm.addColumn("No");
    dtm.addColumn("Ma tham so");
    dtm.addColumn("ten tham so");
    dtm.addColumn("qui dinh");
   
    
    for(ThamSo l:this.cd.thamso()){
        int i=1;
        dtm.addRow(new Object[]{i,l.getMaThamso(),l.getTenThamso(),l.getQuiDinh()});
        i++;
    }
    this.tb_qldb.setModel(dtm);
    this.tb_qldb.repaint();
    this.tb_qldb.revalidate();
    }
    private void bnt_thuthapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnt_thuthapActionPerformed
   // if(evt.equals(true)){jProgressBar1.setStringPainted(true);
     //   jProgressBar1.setIndeterminate(true);}
        queue_url qu=new queue_url();
        int soluong=(int) sp_soluong.getValue();
        System.out.print(soluong);
        thread_queue po=new thread_queue(qu,soluong);
        parse_google_htmlUnit ps= new parse_google_htmlUnit(qu,soluong);
        kiemtra_net ktn=new kiemtra_net();

        if(ktn.kiemtra()==true){
   //  tamthoi tt=new tamthoi();
        //   Thread pb= new Thread(tt);
          // pb.start();
            ps.start();
            po.start();
       
            String y= po.getName();
            System.out.println(y);//la cai goi lay
            String y1= ps.getName();
            System.out.println(y1);
            // String y3= pb.getName();
          //  System.out.println(y3);
            try{
                ps.join();

                po.join();
              //  pb.join();
            }catch(InterruptedException ex){

               // System.out.println("Interrupted"+ex.getMessage());
            }
    }//GEN-LAST:event_bnt_thuthapActionPerformed
    }
   static int i=0;
    private void bnt_nextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnt_nextActionPerformed
     
            
        
       switch(i){
           case 0:
               load_table_thamso();
                i++;
               break;
           case 1:
               load_table_hinh();
                 i++;
               break;
           case 2:
               load_table_thongtin();
                 i++;
                break;
           case 3:
                 load_table_link();
                 i=0;
                break;
       } 
    }//GEN-LAST:event_bnt_nextActionPerformed

    private void btn_backActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_backActionPerformed
         
       switch(i){
           case 0:
               load_table_link();   
                i=3;
               break;
           case 1:
                load_table_thamso();
                 i--;
               break;
           case 2:
                load_table_hinh();
          
                 i--;
                break;
           case 3:
                   load_table_thongtin();
                 
               
                 i--;
                break;
       } 
    }//GEN-LAST:event_btn_backActionPerformed

    private void tb_ketqua_linkMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tb_ketqua_linkMouseClicked
 if(tb_ketqua_link.getSelectedRow() >= 0 )
        {
            int index = tb_ketqua_link.getSelectedRow();
           // txtMaPhong.setText(tbPhong.getValueAt(index, ).toString());
            txt_tieude.setText(tb_ketqua_link.getValueAt(index, 1).toString());
            txt_link.setText(tb_ketqua_link.getValueAt(index, 2).toString());
            
        }
    }//GEN-LAST:event_tb_ketqua_linkMouseClicked

    private void txt_tukhoaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txt_tukhoaMouseClicked
     
    }//GEN-LAST:event_txt_tukhoaMouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
            String a;
             String s="";
            a=txt_tukhoa.getText();
            String arr[];
            arr=a.split(" ");
            for(int i=0;i<arr.length;i++){
          s+=arr[i]+"+";
            }
            int r=s.length();
         String  ss= s.substring(0,r-1);
                     System.out.print(r+ss);
     //   String duong_link="https://vi-vn.facebook.com/diadiemcf";
   //     if(this.cd.xoa(cd.tim_them_vao_tblink(duong_link)))
       // {
         //   System.out.print("co");
       // }else
          //  System.out.print("khong");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void bnt_lammoiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnt_lammoiActionPerformed
      this.tb_qldb.repaint();
        this.tb_qldb.revalidate();
    }//GEN-LAST:event_bnt_lammoiActionPerformed
    public class tamthoi implements Runnable{
    
        @Override
        public void run(){
       // jProgressBar1.setStringPainted(true);
        jProgressBar1.setIndeterminate(true);
        
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                
            }
        
        }
    
    
    
    
    }
    
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bnt_lammoi;
    private javax.swing.JButton bnt_next;
    private javax.swing.JButton bnt_thuthap;
    private javax.swing.JButton bnt_xoa_qldb;
    private javax.swing.JButton btn_back;
    private java.awt.Button button1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JProgressBar jProgressBar2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel la_soluong;
    private javax.swing.JSpinner sp_soluong;
    private javax.swing.JTable tb_ketqua_link;
    private javax.swing.JTable tb_qldb;
    private javax.swing.JTextField txt_link;
    private javax.swing.JTextField txt_tieude;
    private javax.swing.JTextField txt_tukhoa;
    // End of variables declaration//GEN-END:variables
}
